package com.nega.modules.Task;

import com.nega.commons.model.SearchResult;
import com.nega.commons.util.DateUtils;
import com.nega.modules.service.SearchResultService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @Author: Garcia
 * @CreateDate: 2019/06/05 12:32
 * @Description: 定时清除用户搜索前一个小时的数据
 */
@Component
@Slf4j
public class ScheduledClearSearchResult {

    @Resource
    private SearchResultService searchResultService;

    @Scheduled(fixedRate = 60 * 1000 * 5)
    @Async
    public void execute() {
        log.info("开始清除失效数据>>>");
        long start = System.currentTimeMillis();
        String date = DateUtils.date2String(new Date(),DateUtils.YYYY_MM_DD_HH_MM_SS);
        searchResultService.deleteByDate(date);
        log.info("清除完成，耗时:{}",(System.currentTimeMillis() - start));
    }
}
